package com.example.jack.community.view.home.homeAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.jack.community.R;
import com.example.jack.community.data.HomeCommentBean;

import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by vveng on 2017/11/20 21: 41
 *
 * @mail: vvengStruggle@163.com
 * 首页动态详情评论适配器
 */

public class HomeDynamicDetailsAdapter extends RecyclerView.Adapter<HomeDynamicDetailsAdapter.MyViewHolder> {
     private ArrayList<HomeCommentBean> mCommentBeen;
     private Context mContext;

    public HomeDynamicDetailsAdapter(ArrayList<HomeCommentBean> commentBeen, Context context) {
        mCommentBeen = commentBeen;
        mContext = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.home_dynamic_comment_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher);
        Glide.with(mContext).load(mCommentBeen.get(position).getAvatarImage()).apply(options).into(holder.avatarImage);
        holder.username.setText(mCommentBeen.get(position).getUsername());
        holder.context.setText(mCommentBeen.get(position).getContext());
        holder.time.setText(mCommentBeen.get(position).getTime());
    }

    @Override
    public int getItemCount() {
        return mCommentBeen.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private CircleImageView avatarImage ;
        private TextView username;
        private TextView time;
        private TextView context;

        public MyViewHolder(View itemView) {
            super(itemView);
            avatarImage = (CircleImageView) itemView.findViewById(R.id.home1_item_dynamic_comment_tx);
            username = (TextView) itemView.findViewById(R.id.home1_item_dynamic_comment_username);
            time = (TextView) itemView.findViewById(R.id.home1_item_dynamic_comment_time);
            context = (TextView) itemView.findViewById(R.id.home1_item_dynamic_comment_context);
        }
    }
}
